package com.gzq.learn.springbootdemo.mongodb;

import java.net.UnknownHostException;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.SimpleMongoDbFactory;

import com.mongodb.MongoClientURI;

//@Configuration
//@ConfigurationProperties(prefix = "mongodb")
public class MongoConfig {

//    @Value("${mongodb.uri}")
    private String mongodbUri;

//    @Bean
    public MongoTemplate mongoTemplate() throws UnknownHostException {
        return new MongoTemplate(
                new SimpleMongoDbFactory(new MongoClientURI(mongodbUri)));
    }
}
